package javaer.starter.base.domain.vo;

import lombok.Data;

import static javaer.starter.base.domain.vo.ResultVO.ResultConsts.FAILURE_CODE;
import static javaer.starter.base.domain.vo.ResultVO.ResultConsts.SUCCESS_CODE;

/**
 * @author yangzhen
 * @date 2023/6/7 15:47
 * @since 1.0.0
 */
@Data
public class ResultVO<T> {

    private String code;

    private String msg;

    private Boolean success;

    private Long t = System.currentTimeMillis();

    private Object data;

    public ResultVO() {
    }

    public static ResultVO success() {
        return success(null);
    }

    public static <T> ResultVO<T> success(T data) {
        return success(data, SUCCESS_CODE);
    }

    public static <T> ResultVO<T> success(Object data, String code) {
        ResultVO<T> resultVO = new ResultVO();
        resultVO.setSuccess(true);
        resultVO.setData(data);
        resultVO.setCode(code);
        return resultVO;
    }

    public static <T> ResultVO<T> error(String message) {
        return error(message, FAILURE_CODE);
    }

    public static <T> ResultVO<T> error(String message, String code) {
        ResultVO<T> resultVO = new ResultVO();
        resultVO.setSuccess(false);
        resultVO.setMsg(message);
        resultVO.setCode(code);
        return resultVO;
    }

    public interface ResultConsts {
        String SUCCESS_CODE = "200";
        String FAILURE_CODE = "500";
        String PARAM_MISSING = "1109";
        String TOKEN_STATUS_INVALID = "1012";
    }
}
